import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.math.BigDecimal;

import lejos.pc.comm.NXTConnector;

public class Main {
	/** 
	 * @param args
	 */	
	public static void main(String[] args) {
		RobotWindow roboWin= new RobotWindow();

		//java.io.File f = new java.io.File("c:\\teste.txt");

		//DataOutputStream dto = new DataOutputStream() )



		try {


			NXTConnector nxtconn = new NXTConnector();

			if( nxtconn.connectTo("btspp://NXT"))  
			{			
				DataInputStream ipts = nxtconn.getDataIn();
				DataOutputStream opts = nxtconn.getDataOut();

				try {

					String in= ""; 
					while (in != null)
					{
						in = ipts.readLine();						

						String valores[] = in.split(":");		
						BigDecimal b = new BigDecimal(valores[0]); 
						System.out.println("\n Recebi " + in + " |||x~" +  b) ;
						//System.out.println(valores[0] + " " +  valores[1] + " " + valores[2] );

						roboWin.updateValues(Double.parseDouble(valores[0])  , Double.parseDouble(valores[1]));
						roboWin.execute();
					}			    	 

				} catch (IOException e1) {
					// TODO Auto-generated catch block
					System.out.println("\n Erro ! ioException");
					e1.printStackTrace();

				}
				finally
				{
					nxtconn.close();
					System.out.println("\n Comms Fechadas !");
				}

			}
			else
			{
				System.out.println("Erro ligando ao NXT");

			}

		} catch (Exception e) { }

	}
}
